//引入API
import { createRouter, createWebHashHistory } from "vue-router";

//引入了两个界面


const Home = () => import("../views/Home.vue");
const About = () => import("../views/About.vue");
const UserCenter = () => import("../views/user-center/index.vue");
const UserProfile = () => import("../views/user-center/Profile.vue");
const UserSettings = () => import("../views/user-center/Settings.vue");
const Product = () => import("../views/Product.vue");
const VuexPage = () => import("../views/Vuex.vue");
const AxiosTest = () => import("../views/AxiosTest.vue");

// 404
const NotFound = () => import("../views/404.vue");

const routes = [
    {
        path: '/', redirect: '/home',
    },
    {
        path: '/home',
        name: "home",
        component: Home
    },
    {
        path: '/about',
        name: "about",
        component: About
    },
    {
        path: "/user",
        name: "userCenter",
        component: UserCenter,
        redirect: '/user/profile',
        children: [
            {
                path: "profile",
                name: "profile",
                component: UserProfile
            },
            {
                path: "settings",
                name: "settings",
                component: UserSettings
            },
        ],

    },
    {
        path: '/product/:id',
        name: 'product',
        component: Product
    },
    {
        path: '/vuex',
        name: '/vuex',
        component: VuexPage
    },
    {
        path: '/axios-test',
        name: '/axiosTest',
        component: AxiosTest
    },
    {
        path: '/:pathMatch(.*)*',
        name: 'NotFound',
        component: NotFound
    },

]

// 创建了一个路由的实例化对象
const router = createRouter({
    history: createWebHashHistory(),
    routes
});
//home
//about

router.beforeEach((to, from, next) => {
    console.log('to', to);
    console.log('from', from);
    next()
})

router.afterEach((to, from) => {
    console.log('afterEach==========');
    console.log('to', to);
    console.log('from', from);
})

export default router

